﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

using XGameFrame;
using XGameFrame.Collision;
using XGameFrame.Graphic;
using XGameFrame.Controls;

using XTowerDef.GameScreens.GamePlayElements;

namespace XTowerDef.GameScreens
{
    public class GamePlayScreen:BaseGameState
    {
        #region Field Region
        //Test Graphic for Animation
        Background backgroundImage;
        AnimatedCreepSprite testCreep;
        AnimatedCreepSprite testCreep2;
        Texture2D creep;
        CreepParticleEngine creepEngine;

        FpsCounter fpsCounter;

        //TESTREGION
        MapBase myMap;
        // ENDTESTREGION
        #endregion

        #region Property Region
        #endregion

        #region Constructor Region

        public GamePlayScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {

        }

        #endregion

        #region XNA Method Region

        public override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();

            //Testing animated Graphics
            ContentManager Content = Game.Content;

            // the Picture for the Background
            backgroundImage = new Background(
                Content.Load<Texture2D>(@"Backgrounds\gameplayscreen2"), Content.Load<Texture2D>(@"Backgrounds\gameplayscreen2move"), GameRef.ScreenRectangle);
            // add the PictureBox to the ControlManager how will add the control to the 
            ControlManager.Add(backgroundImage);

            creep = Content.Load<Texture2D>(@"GameGraphics\Creeps\SmileyWalk");
            testCreep = new AnimatedCreepSprite(creep, 4, 4, new Vector2(0, 0));
            testCreep2 = new AnimatedCreepSprite(creep, 4, 4, new Vector2(250, 250));
            AnimatedSpriteManager.Add(testCreep);
            AnimatedSpriteManager.Add(testCreep2);
            creepEngine = new CreepParticleEngine(testCreep2, Game.Content);
            fpsCounter = new FpsCounter(new Vector2(400, 100));
            ControlManager.Add(fpsCounter);
            myMap = new HexagonalMap(new TileHandler(Content.Load<Texture2D>(@"Maps\TileSets\testtileset"), new Vector2(32, 32), MapBase.MapType.TileMap), 50, 50);
            MapManager.Add(myMap);
        }

        public override void Update(GameTime gameTime)
        {
            ControlManager.Update(gameTime, playerIndexInControl);
            AnimatedSpriteManager.Update(gameTime, playerIndexInControl);
            base.Update(gameTime);


            this.creepEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            this.testCreep2.Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            this.creepEngine.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            MapManager.Draw(GameRef.SpriteBatch);
            GameRef.SpriteBatch.Begin();
            base.Draw(gameTime);
            if(!CollisionHandler.CheckOpaqueCollison(testCreep, testCreep2))
                AnimatedSpriteManager.Draw(GameRef.SpriteBatch);
            GameRef.SpriteBatch.End();
            this.creepEngine.Draw(GameRef.SpriteBatch);
        }

        #endregion

        #region Abstract Method Region
        #endregion


    }
}
